package com.btpj.login_db.controller;

import com.btpj.login_db.entity.RespBean;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloController {

    @GetMapping("/hello")
    public String hello() {
        return "hello,SpringSecurity";
    }

    @GetMapping("/user/hello")
    public String userHello() {
        return "userHello";
    }

    @GetMapping("/admin/hello")
    public String adminHello() {
        return "adminHello";
    }

    @GetMapping("/userInfo")
    public RespBean getUserInfo() {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        return RespBean.success(authentication.getPrincipal());
    }
}
